// ------------------------------------------------------------------------------------ App - Web公共登录部分
function commonSignIn() {
    // 1.判断登录
    if (_Global_ == 'web') {
        // H5未登录
        if (!iLogin()) {
            alertVerification();
            return false;
        }
    } else if (_Global_ == 'app') {
        // app未登录
        if (phone == null || phone == 'null' || phone == '') {
            signIn();// app的登录
            return false;
        }
    }
    return true;
}
//手机正则
function isPhoneNumber(nub) {
    var myreg = /^1[34578]\d{9}$/;
    if (!myreg.test(nub)) {
        return false;
    }
    return true;
}
// ----------------------------------------------------------------- 倒计时
var CDtimer = null //倒计时定时器
function countDown() {
    var count = 60;
    CDtimer = setInterval(function () {
        if (count > 0) {
            count--;
            phone_code_get.html(count + 's后可重发');
        } else {
            clearInterval(CDtimer);
            phone_code_get.html('获取验证码');
            codeKey = true;
        }
    }, 1000)
}
// ----------------------------------------------------------------- 验证码发送
function sendMsgCode(phone) {
    $.ajax({
        url: getIp + '/CARNT/loli/sendVerifyCode',
        type: "post",
        dataType: "json",
        data: {
            PHONE: phone
        },
        success: function (data) {
            if (data.STATUS_CODE == 1) {// 正常返回
                codeKey = false;// 改变状态为false 不可再发送验证码
                countDown();//开始倒计时
            } else {
                alert('请重新获取');
            }
        }
    });
}
// ----------------------------------------------------------------- 获取验证码
phone_code_get.on('click', function () {
    var p = phone_number.val();   //电话号码
    if (p == '') {
        $('.alertWord').text('手机号码不能为空').show();
        return;
    }
    if (isPhoneNumber(p)) {// 通过手机号码格式验证
        if (codeKey) {
            sendMsgCode(p);// 发送验证码
        }
    } else {
        $('.alertWord').text('手机号码有误').show();
        return;
    }
});
// ----------------------------------------------------------------- 去登陆
toLogin.on('click', function () {
    var phoneNumber = phone_number.val();   //电话号码
    var codeNumber = phone_code.val();  //验证码输入框的值
    if (phoneNumber == '') {
        $('.alertWord').text('手机号码不能为空').show()
        return;
    }
    if (!isPhoneNumber(phoneNumber)) {
        $('.alertWord').text('手机号码有误').show()
        return;
    }
    if (codeNumber == '') {
        $('.alertWord').text('验证码不能为空').show()
        return;
    }
    verification.hide();
    maskBg.hide();
    //清空输入框
    phone_code.val("");
    phone_code_get.html('获取验证码');
    var unionid = getCookie('_unionidpo_');
    var sendObj = {UNIONID: unionid, USERNAME: phoneNumber, VERIFY_CODE: codeNumber, 'LOGIN_SYSTEM': 'web'};
    // 验证-验证码
    $.ajax({
        url: getIp + '/CARNT/UserWeb/signIn.action',
        type: "post",
        dataType: "json",
        data: sendObj,
        success: function (data) {
            if (data.STATUS_CODE == 1) {// 正常返回
                //存储用户登录后的信息
                setCookie('loginkey', data.USER.USER_ID);
                setCookie('name', data.USER.USERNAME);
                setCookie('userName', data.USER.USERNAME);
                if (rollFlag) {
                    $("#lottery #startDraw").trigger("click");
                }
            } else if (data.STATUS_CODE == 2) {// 验证码错误或已过期
                promptBox('验证码错误或已过期！', ' ');
            } else {
                promptBox('验证验证码失败！', ' ');
            }
        }
    });
});

// ----------------------------------------------------------------- web登录部分
function alertVerification() {
    $('.verification').show();
    $('.mask').show();
}
// ------------------------------------------------------------------------------------ web登录检测（不直接调用）
var iLogin = function () {
    if (getCookie('loginkey') && getCookie('userName')) {// 已登录
        return true;
    } else {// 未登录
        return false;
    }
}
// 关闭弹窗
$(".close,.mask,.downloadClose,.close2,.toLogin,.iKnow").on("click", function (event) {
    verification.hide();
    zhongRecord.hide();
    maskBg.hide();
    zhongBox.hide();
    $(".drawRulePages").hide();
    $('.yellowRelative').hide();
    $('.youHaveNot').hide();
    $(".drawRecord").hide();
    $(".drawResult").hide();
    $('.promptBox').hide();
    $('.promptBox1').hide();
})

//ios11 使用绝对定位input框焦点偏移的解决办法
$("#phoneN,#codeN").click(function(ev){
	var ev = ev || event;
	ev.stopPropagation();
	$("body").css('position','fixed');
	$("body").css('overflow','hidden');
})
$(document).click(function(){
	$("body").css('position','static');
	$("body").css('overflow','auto');
})